epithet_erasedfandomcom-20200213-history
Talk:Sylvester Ashling/@comment-38126337-20200208025714
| family = | released = | designer = Lars Bak and Kasper Lund | developer = Google | latest release version = 2.7.0 | latest release date = | latest preview version = 2.8.0-dev.0.0 | latest preview date = | typing = 1.x: Optional, 2.x: Static | scope = | implementations = Dart VM, dart2js, DDC, Flutter | dialects = | influenced by = C#, Erlang, JavaScript, Kotlin , Smalltalk, Strongtalk | influenced = | programming language = | platform = Cross-platform | operating system = Cross-platform | license = BSD | website = | file ext = .dart | fileformat = }} Dart is a client-optimized programming language for apps on multiple platforms. It is developed by Google and is used to build mobile, desktop, backend and web applications. Dart is an object-oriented, class defined, garbage-collected language using a C-style syntax that transcompiles optionally into JavaScript. It supports interfaces, mixins, abstract classes, reified generics, static typing, and a sound type system. History Dart was unveiled at the GOTO conference in Aarhus, Denmark, October 10–12, 2011. The project was founded by Lars Bak and Kasper Lund. Dart 1.0 was released on November 14th, 2013. In August 2018, Dart 2.0 was released, with language changes including a sound type system. Recently release Dart 2.6 is accompanied with a new extension dart2native. The feature extends native compilation to the Linux, MacOS, and Windows desktop platforms. Earlier developers were able to create new tools only using Android or iOS devices. Moreover, with this extension it becomes possible to compose a Dart program into self-contained executables. Thus, according to the company representatives, it’s not obligatory now to have Dart SDK installed, the self-contained executables can now start running in a few seconds. The new extension is also integrated with Flutter toolkit, thus making it possible to use the compiler on small services (backend supporting for example). ;Standardization Ecma International has formed technical committee TC52 to work on standardizing Dart, and inasmuch as Dart can be compiled to standard JavaScript, it works effectively in any modern browser. Ecma International approved the Dart language specification first edition in July 2014, at its 107th General Assembly, and a second edition in December 2014. The latest specification is available at Dart language specification. Usage There are four ways to run Dart code: ;Compiled as JavaScript: To run in mainstream web browsers, Dart relies on a source-to-source compiler to JavaScript. According to the project site, Dart was "designed to be easy to write development tools for, well-suited to modern app development, and capable of high-performance implementations." When running Dart code in a web browser the code is precompiled into JavaScript using the dart2js compiler. Compiled as JavaScript, Dart code is compatible with all major browsers with no need for browsers to adopt Dart. Through optimizing the compiled JavaScript output to avoid expensive checks and operations, code written in Dart can, in some cases, run faster than equivalent code hand-written using JavaScript idioms. ;Stand-alone:The Dart software development kit (SDK) ships with a stand-alone Dart VM, allowing Dart code to run in a command-line interface environment. As the language tools included in the Dart SDK are written mostly in Dart, the stand-alone Dart VM is a critical part of the SDK. These tools include the dart2js compiler and a package manager called pub. Dart ships with a complete standard library allowing users to write fully working system apps, such as custom web servers. ;Ahead-of-time compiled:Dart code can be AOT-compiled into machine code (native instruction sets). Apps built with Flutter, a mobile app SDK built with Dart, are deployed to app stores as AOT-compiled Dart code. ;Native:Dart 2.6 with dart2native compiler to compile to self-contained, native executables code. Before Dart 2.6, this feature only exposed this capability on iOS and Android mobile devices via Flutter. Isolates To achieve concurrency, Dart uses isolates, which are independent workers that do not share memory, but instead use message passing. This is similar to Erlang processes (see also Actor model). Every Dart program uses at least one isolate, which is the main isolate. Since Dart 2 the Dart web platform no longer supports isolates, and suggests developers use Web Workers instead. Snapshots Snapshots are a core part of the Dart VM. Snapshots are files which store objects and other runtime data. ;Script snapshots :Dart programs can be compiled into snapshot files. These files contain all of the program code and dependencies preparsed and ready to execute. This allows fast startups. ;Full snapshots :The Dart core libraries can be compiled into a snapshot file which allows fast loading of the libraries. Most standard distributions of the main Dart VM have a prebuilt snapshot for the core libraries which is loaded at runtime. ;Object snapshots :Dart is a very asynchronous language. With this, it uses isolates for concurrency. Since these are workers which pass messages, it needs a way to serialize a message. This is done using a snapshot, which is generated from a given object, and then this is transferred to another isolate for deserializing. Native mobile apps Google has introduced Flutter for native mobile app development on both Android and iOS. Flutter is a mobile app SDK, complete with framework, widgets, and tools, that gives developers a way to build and deploy mobile apps, written in Dart. Flutter works with Firebase and other mobile app SDKs, and is open source. Compiling to JavaScript The Dart SDK contains two Dart-to-JavaScript compilers. During development, dartdevc supports quick refresh cycles. For the final version of an app, dart2js produces deployable JavaScript. The first compiler to generate JavaScript from Dart code was dartc, but it was deprecated. The second Dart-to-JavaScript compiler was Frog. It was written in Dart, but never implemented the full semantics of the language. The third Dart-to-JavaScript compiler was dart2js. An evolution of earlier compilers, dart2js is written in Dart and intended to implement the full Dart language specification and semantics. On March 28, 2013, the Dart team posted an update on their blog addressing Dart code compiled to JavaScript with the dart2js compiler, stating that it now runs faster than handwritten JavaScript on Chrome's V8 JavaScript engine for the DeltaBlue benchmark. Editors On November 18, 2011, Google released Dart Editor, an open-source program based on Eclipse components, for Mac OS X, Windows, and Linux-based operating systems. The editor supports syntax highlighting, code completion, JavaScript compiling, running web and server Dart applications, and debugging. On August 13, 2012, Google announced the release of an Eclipse plugin for Dart development. On April 18, 2015, Google announced that the Dart Editor would be retired in favor of the JetBrains integrated development environment (IDE), which is now the recommended IDE for the language. The Dart plugin is available for IntelliJ IDEA, PyCharm, PhpStorm and WebStorm. This plugin supports many features such as syntax highlighting, code completion, analysis, refactoring, debugging, and more. Other plugins are available for editors like Sublime Text, Atom, Emacs, Vim and Visual Studio Code. Chrome Dev Editor In 2013, the Chromium team began work on an open source, Chrome App-based development environment with a reusable library of GUI widgets, codenamed Spark. The project was later renamed as Chrome Dev Editor. It was built in Dart, and contained Spark which is powered by Polymer. In June 2015, Google transferred the CDE project to GitHub as a free software project and ceased active investment in CDE. As of April 2019 Chrome Dev Editor is no longer in active development. DartPad The Dart team created DartPad at the start of 2015, to provide an easier way to start using Dart. It is a fully online editor from which users can experiment with Dart application programming interfaces (APIs), and run Dart code. It provides syntax highlighting, code analysis, code completion, documentation, and HTML and CSS editing. SIMD In 2013, John McCutchan announced that he had created a performant interface to single instruction, multiple data (SIMD) instruction sets for Dart. The interface consists of two types: * Float32×4, 4× single precision floating point values * Uint32×4, 4× 32-bit unsigned integer values Instances of these types are immutable and in optimized code are mapped directly to SIMD registers. Operations expressed in Dart typically are compiled into one instruction with no overhead. This is similar to C and C++ intrinsics. Benchmarks for 4×4 matrix multiplication, 3D vertex transformation, and Mandelbrot set visualization show near 400% speedup compared to scalar code written in Dart. Example A Hello World example: main() { print('Hello World!'); } A function to calculate the nth Fibonacci number: int fib(int n) => (n > 2) ? (fib(n - 1) + fib(n - 2)) : 1; // this is a fibonacci function implementation with a ternary operator in Dart // this code shall be read as: // If int n > 2, return fib(n - 1) + fib(n - 2); // otherwise, return int 1 as result void main() { print('fib(20) = ${fib(20)}'); } A simple class: // Import the math library to get access to the sqrt function. import 'dart:math' as math; // Create a class for Point. class Point { // Final variables cannot be changed once they are assigned. // Create two instance variables. final num x, y; // A constructor, with syntactic sugar for setting instance variables. // The constructor has two mandatory parameters Point(this.x, this.y); // A named constructor with an initializer list. Point.origin() : x = 0, y = 0; // A method. num distanceTo(Point other) { var dx = x - other.x; var dy = y - other.y; return math.sqrt(dx * dx + dy * dy); } // Example of Operator Overloading Point operator +(Point other) => Point(x + other.x, y + other.y); // When you instantiate a class such as Point in Dart 2+, new is // an optional word } // All Dart programs start with main(). void main() { // Instantiate point objects. var p1 = Point(10, 10); var p2 = Point.origin(); var distance = p1.distanceTo(p2); print(distance); } Influences from other languages Dart is a descendant of the ALGOL language family, alongside C, Java, C#, JavaScript, and others. The method cascade syntax, which provides a syntactic shortcut for invoking several methods one after another on the same object, is adopted from Smalltalk. Dart's mixins were influenced by Strongtalk and Ruby. Dart makes use of isolates as a concurrency and security unit when structuring applications. The Isolate concept builds upon the Actor model, which is most famously implemented in Erlang. The Mirror API for performing controlled and secure reflection was first proposed in a paper by Gilad Bracha (who is a member of the Dart team) and David Ungar and originally implemented in Self. Criticism Dart initially had a mixed reception and the Dart initiative has been criticized by some for fragmenting the web, due to the original plans to include a Dart VM in Chrome. Those plans were dropped to focus instead on compiling Dart to JavaScript. See also * CoffeeScript * Elm (programming language), a compile-to-JavaScript functional language with static typing * Fantom (programming language) * Go, another language developed by Google * Google Web Toolkit * Haxe, a language that can be compiled to JavaScript and several other languages * Reason * Opa (programming language) * TypeScript, a strongly-typed programming language that transpiles to JavaScript * Kotlin References Bibliography * * * External links * * DartPad Category:Articles with example code Category:C programming language family Category:Concurrent programming languages Category:Dynamically typed programming languages Category:Google software Category:JavaScript programming language family Category:Object-oriented programming languages Category:Programming languages created in 2011 Category:Scripting languages Category:Software using the BSD license Category:Web programming Category:Free software projects Category:2011 software Category:Source-to-source compilers